from django.shortcuts import *

# Create your views here.
class User(object):
    def __init__(self,name,pwd):
        self.name = name
        self.pwd = pwd
        #重写方法，隐藏密码
    def __getstate__(self):
        data = self.__dict__.copy()
        del data['pwd']
        return data
import jsonpickle
def login(request):
    if request.method=='GET':
        return render(request,'login.html')
    else:
        name = request.POST.get('name')
        pwd = request.POST.get('pwd')
        if name =='qq' and pwd =='12':
            user = User(name,pwd)
            #jsonpickle.dumps(user)将python对象序列化普通字符串
            request.session['login']=jsonpickle.dumps(user)
            return redirect(reverse('gr'))
    return None


def gr(request):
    res = request.session['login']
    # 将普通字符串反序列化python对象
    uuser = jsonpickle.loads(res)

    return render(request,'gr.html',{'res':uuser})